﻿@model IEnumerable<Backend.JYD.Model.Cust.CustBase>
@using Backend.JYD.Business;
@using Backend.JYD.Web.Common
@{
    ViewBag.Title = "客户查询";
    Layout = "~/Views/Shared/_LayoutWin.cshtml";
    var mgr = new CodeManager();
}

<form action="/cust/searchall" method="get">
<div class="ui_pop_body" style="width: 900px; height: 600px;">
    <div>
        <ul class="edit-ul">
        @if(this.ViewBag.CustType != "real")
        {
            <li class="li01">
                <span class="s01">客户源：</span>
                <span class="s02">
                    <label for="rdType1"><input type="radio" @(new HtmlString(ViewBag.CustType != "2" && ViewBag.CustType != "3" ? "checked=\"checked\"" : string.Empty)) name="rdtype" id="rdType1" value="1"/>正式客户</label>
                    <label for="rdType2"><input type="radio" @(new HtmlString(ViewBag.CustType == "2" ? "checked=\"checked\"" : string.Empty)) name="rdtype" id="rdType2" value="2"/>意向客户</label>
                    <label for="rdType3"><input type="radio" @(new HtmlString(ViewBag.CustType == "3" ? "checked=\"checked\"" : string.Empty)) name="rdtype" id="rdType3" value="3"/>营销客户</label>
                </span>
            </li>
            }
            <li class="li01">
                <span class="s01">证件类型：</span>
                <span class="s02">@Html.DropDownList("rdoInfoType", JydHtmlHelper.ConvertItemFormCodeInfo("请选择", CodeManager.PaperType, "1"), new { style = "width:120px;" })
                渠道来源：@Html.DropDownList("rdoChanelType", JydHtmlHelper.ConvertItemFormCodeInfo("全部", CodeManager.CustChanelType, string.Empty), new { style = "width:120px;" })</span>
            </li>
            <li class="li01">
                <span class="s01">客户号：</span>
                <span class="s02">
                <input type="text" style="width:120px;" name="custno" id="custno" value="@ViewBag.CustNo"/>
                客户姓名：<input type="text" style="width:120px;" name="name" id="name" value="@ViewBag.CustName"/>
                客户电话：<input type="text" style="width:120px;" name="phone" id="phone" value="@ViewBag.Phone"/>
                </span>
            </li>
            
            <li class="li01">
                <span class="s01"></span>
                <span class="s02">
                    <input type="button" value="查询" onclick="loadpage()"/>
                    <input type="button" value="关闭" onclick="closeWin()"/>
                    <input type="button" value="选择" onclick="choose()"/>
                </span>
            </li>
            <li>
                <span class="s01">正式客户：</span>
                <span class="s02">指有客户号的客户数据。</span>
            </li>
             <li>
                <span class="s01">意向客户：</span>
                <span class="s02">指有来源于意向信息的客户数据。查询条件客户号无效。</span>
            </li>
             <li>
                <span class="s01">正式客户：</span>
                <span class="s02">指有来源于意向信息的客户数据。查询条件客户号无效、渠道无效。</span>
            </li>
        </ul>
    </div>
     <table class="table1" width="100%" border="0" cellpadding="0" cellspacing="1">
        <thead>
            <tr>
                <th width="10px" align="center"><div class="th1"></div></th>
                <th width="10px" align="center"><div class="th1"></div></th>
                <th width="90px" align="center"><div class="th1">客户号</div></th>
                <th width="80px" align="center"><div class="th1">姓名</div></th>
                <th width="50px" align="center"><div class="th1"></div></th>
                <th width="50px" align="center"><div class="th1">证件类型</div></th>
                <th width="130px" align="center"><div class="th1">证件号码</div></th>
                <th width="100px" align="center"><div class="th1">电话</div></th>
                <th width="60px" align="center"><div class="th1">来源渠道</div></th>
                @*<th width="7px"><div class="th1"></div></th>*@
            </tr>
        </thead>
         <tbody>
            @if (Model != null)
            {
                int idx = 0;
                foreach (var info in Model)
                {
                    idx++;
                    string chanelName = !info.ChanelType.HasValue ? string.Empty : CodeManager.GetCodeNameByTypeCode(CodeManager.CustChanelType, info.ChanelType.ToString());
                    string PaperName = string.IsNullOrWhiteSpace(info.PaperType) ? string.Empty : CodeManager.GetCodeNameByTypeCode(CodeManager.PaperType, info.PaperType.ToString());
                <tr>
                    <td>@idx</td>
                    <td>
                        <input type="radio" value="@idx" name="chkNo"/>
                        <input type="hidden" value="@info.PaperType" id="@("ptype_" + idx)" />
                        <input type="hidden" value="@info.ChanelType" id="@("channel_" + idx)" />
                    </td>
                    <td id="@("cno_" + idx)">@info.CustNo</td>
                    @if(string.IsNullOrWhiteSpace(info.CustNo)){
                    <td id="@("cname_" + idx)">@info.CustName</td>
                        }else{
                    <td><a href="/cust/index?no=@info.CustNo" target="_blank" id="@("cname_" + idx)">@info.CustName</a></td>
                        }
                    <td>@(!string.IsNullOrWhiteSpace(info.CustNo) ? "正式客户" : (this.ViewBag.CustType == "3" ? "营销客户" : "意向客户"))</td>
                    <td>@PaperName</td>
                    <td id="@("pno_" + idx)">@info.PaperNo</td>
                    <td id="@("cphone_" + idx)">@info.Phone</td>
                    <td>@chanelName</td>
                </tr>
                }
            }
            
         </tbody>
    </table>
    @{
            Html.RenderPartial("_Pager");
        }
</div>
</form>
<script type="text/javascript">
    function loadpage() {
        var custno = $("#custno").val();
        var name = $("#name").val();
        var phone = $("#phone").val();
        var chanel = $("input[name='rdoChanelType']").val();
        var type = $("input[name='rdtype']:checked").val(); 
//        if (!custno && !name && !phone) {
//            alert('请输入查询条件。');
//            return;
//        }
        url = "/cust/searchall?&page=1";
        if (type && (type == "2" || type == "3")) {
            url += "&type=" + type;
        }
        if (chanel) {
            url += "&chanel=" + chanel;
        }
        if (custno) {
            url += "&no=" + custno;
        }
        if (name) {
            url += "&name=" + escape(name);
        }
        if (phone) {
            url += "&phone=" + phone;
        }

        window.location = url;
    }

    function choose() {
        var idx = $("input[name='chkNo']:checked").val();
//        if (!no) {
//            alert("请选择客户。");  
//            return;
        //        }
        var no = $("#cno_" + idx).text();
        var name = $("#cname_" + idx).text();
        var ptype = $("#ptype_" + idx).val();
        var pno = $("#pno_" + idx).text();
        var cphone = $("#cphone_" + idx).text();
        var channel = $("#channel_" + idx).val();
        if (window.dialogArguments) {
            window.dialogArguments.returnChoose(no, name, ptype, pno, cphone, channel);
            window.close();
        }
    }

</script>
